<template>
    <view class="container">
        <view class="header">
            <sort-bar
                @__l="
                    __l($event, {
                        eventOpts: [
                            ['^setSort', [['setSort']]],
                            ['^setType', [['setType']]]
                        ]
                    })
                "
                @setSort="
                    __e($event, {
                        eventOpts: [
                            ['^setSort', [['setSort']]],
                            ['^setType', [['setType']]]
                        ]
                    })
                "
                @setType="
                    __e($event, {
                        eventOpts: [
                            ['^setSort', [['setSort']]],
                            ['^setType', [['setType']]]
                        ]
                    })
                "
                :data-event-opts="[
                    ['^setSort', [['setSort']]],
                    ['^setType', [['setType']]]
                ]"
                :defaultItemType="itemType"
                vueId="bda12f3c-1"
                v-if="isShowSortBar"
            ></sort-bar>
        </view>
        <view class="product-list" v-if="isShowSortBar">
            <product-list @__l="__l" :list="list" vueId="bda12f3c-2"></product-list>
            <no-more @__l="__l" vueId="bda12f3c-3"></no-more>
        </view>
        <view class="product-list guest-list" v-else>
            <view class="guess-title">猜你喜欢</view>
            <product-list @__l="__l" :list="guessList" vueId="bda12f3c-4"></product-list>
        </view>
        <no-data @__l="__l" vueId="bda12f3c-5" v-if="$root.g0"></no-data>
    </view>
</template>

<script>
import productList from '@/pages/search/components/list';
import noMore from '@/components/NoMore/NoMore';
import noData from '@/components/NoData/NoData';
import sortBar from '@/pages/search/components/sortBar';
import tabBar from '@/components/TabBar/tabBar';
(global.webpackJsonp = global.webpackJsonp || []).push([
    ['pages/search/index'],
    {
        '0ee8': function (t, e, i) {},
        '19cb': function (t, e, i) {
            'use strict';

            (function (t, e) {
                var n = i('4ea4');
                i('18ba');
                n(i('66fd'));
                var a = n(i('b3e5'));
                t.__webpack_require_UNI_MP_PLUGIN__ = i;
                e(a.default);
            }.call(this, i('bc2e').default, i('543d').createPage));
        },
        '3c50': function (t, e, i) {
            'use strict';

            i.r(e);
            var n = i('ff4c');
            var a = i.n(n);
            for (var o in n) {
                if (['default'].indexOf(o) < 0) {
                    (function (t) {
                        i.d(e, t, function () {
                            return n[t];
                        });
                    })(o);
                }
            }
            e.default = a.a;
        },
        6025: function (t, e, i) {
            'use strict';

            i.d(e, 'b', function () {
                return a;
            });
            i.d(e, 'c', function () {
                return o;
            });
            i.d(e, 'a', function () {
                return n;
            });
            var n = {
                ProductList: function () {
                    return i.e('components/ProductList/ProductList').then(i.bind(null, '0cf8'));
                },
                NoMore: function () {
                    return i.e('components/NoMore/NoMore').then(i.bind(null, '0ffd'));
                },
                NoData: function () {
                    return i.e('components/NoData/NoData').then(i.bind(null, 'cafe'));
                }
            };
            var a = function () {
                this.$createElement;
                var t = (this._self._c, this.init && !this.list.length);
                this.setData(
                    Object.assign(
                        {},
                        {
                            $root: {
                                g0: t
                            }
                        }
                    )
                );
            };
            var o = [];
        },
        '949f': function (t, e, i) {
            'use strict';

            var n = i('0ee8');
            i.n(n).a;
        },
        b3e5: function (t, e, i) {
            'use strict';

            i.r(e);
            var n = i('6025');
            var a = i('3c50');
            for (var o in a) {
                if (['default'].indexOf(o) < 0) {
                    (function (t) {
                        i.d(e, t, function () {
                            return a[t];
                        });
                    })(o);
                }
            }
            i('949f');
            var s = i('f0c5');
            var r = Object(s.a)(a.default, n.b, n.c, false, null, null, null, false, n.a, void 0);
            e.default = r.exports;
        },
        ff4c: function (t, e, i) {
            'use strict';

            (function (t) {
                var n = i('4ea4');
                Object.defineProperty(e, '__esModule', {
                    value: true
                });
                e.default = void 0;
                var a = n(i('2eee'));
                var o = n(i('c973'));
                var s = n(i('448a'));
                var r = {
                    mixins: [n(i('452d')).default],
                    components: {
                        ProductList: function () {
                            i.e('pages/search/components/list')
                                .then(
                                    function () {
                                        return resolve(i('6f0a'));
                                    }.bind(null, i)
                                )
                                .catch(i.oe);
                        },
                        SortBar: function () {
                            i.e('pages/search/components/sortBar')
                                .then(
                                    function () {
                                        return resolve(i('2c55'));
                                    }.bind(null, i)
                                )
                                .catch(i.oe);
                        }
                    },
                    data: function () {
                        return {
                            sort: '',
                            key: '',
                            visible: false,
                            category: [],
                            list: [],
                            page: 1,
                            per_page: 20,
                            total: 0,
                            activeCategory: '',
                            init: false,
                            title: '全部商品',
                            action: '',
                            itemType: 'all',
                            loading: false
                        };
                    },
                    computed: {
                        isShowSortBar: function () {
                            return !('search' === this.action && !this.key);
                        },
                        guessList: function () {
                            return this.list.slice(0, 6);
                        }
                    },
                    watch: {
                        key: function (t) {
                            this.page = 1;
                            this.list = [];
                            this.getProductList();
                        },
                        sort: function (t) {
                            this.page = 1;
                            this.list = [];
                            this.getProductList();
                        },
                        itemType: function (t) {
                            this.page = 1;
                            this.list = [];
                            this.getProductList();
                        }
                    },
                    onLoad: function (e) {
                        var that = this;
                        this.activeCategory = e.category_id || 0;
                        this.title = e.title;
                        this.action = e.action;
                        this.itemType = e.type || 'all';
                        if (this.activeCategory && !this.title) {
                            this.$http('/categories/' + this.activeCategory).then(function (e) {
                                that.title = e.data.info.title;
                                t.setNavigationBarTitle({
                                    title: that.title
                                });
                            });
                        } else {
                            t.setNavigationBarTitle({
                                title: this.title
                            });
                        }
                        this.getProductList();
                        this.$visitor.record('search');
                    },
                    methods: {
                        setSort: function (t) {
                            this.sort = t;
                        },
                        setType: function (t) {
                            this.itemType = t;
                        },
                        activeChange: function (t) {
                            var e = t.currentTarget.dataset.id;
                            this.activeCategory = e == this.activeCategory ? '' : e;
                            this.visible = false;
                            this.getProductList();
                        },
                        handleChange: function (t) {
                            var e = t.currentTarget.dataset.index;
                            var i = this.category[e];
                            0 !== i.sub_categories.length
                                ? (this.category[e].openSubCategory = !this.category[e].openSubCategory)
                                : ((this.activeCategory = i.id), (this.visible = false), this.getProductList());
                        },
                        handleClick: function (e) {
                            t.navigateTo({
                                url: '/pages/productDetail/index?uuid=' + e.uuid
                            });
                        },
                        getProductList: function () {
                            var that = this;
                            this.loading = true;
                            t.showLoading({
                                mask: true
                            });
                            this.$http('/search', 'POST', {
                                category_id: this.activeCategory,
                                page: this.page,
                                key: this.key,
                                sort: this.sort,
                                item_type: this.itemType
                            }).then(function (i) {
                                var n;
                                that.init = true;
                                t.hideLoading();
                                (n = that.list).push.apply(n, (0, s.default)(i.data.list));
                                that.loading = false;
                                that.page++;
                            });
                        },
                        showDrawer: function () {
                            this.visible = true;
                        },
                        drawerClose: function () {
                            this.visible = false;
                        }
                    },
                    onReachBottom: function () {
                        var that = this;
                        return (0, o.default)(
                            a.default.mark(function e() {
                                return a.default.wrap(function (e) {
                                    for (;;) {
                                        switch ((e.prev = e.next)) {
                                            case 0:
                                                if (!that.loading) {
                                                    e.next = 2;
                                                    break;
                                                }
                                                return e.abrupt('return');
                                            case 2:
                                                that.getProductList();
                                            case 3:
                                            case 'end':
                                                return e.stop();
                                        }
                                    }
                                }, e);
                            })
                        )();
                    }
                };
                e.default = r;
            }.call(this, i('543d').default));
        }
    },
    [['19cb', 'common/runtime', 'common/vendor']]
]);
</script>
<style>
@import './index.css';
</style>
